#!/bin/bash

#Some Variables:
firstvar=1;
secondvar=2;
filename=workers.properties;
#thirdvar=xueyuan;
#port=1000;

#Filter the first line of the file and make it as the first part. 
head -n $firstvar $filename > work1.txt

#Filter the line after the first and make them as the second part.
more +$secondvar $filename > work2.txt

#Modify those two part
echo `head -n $firstvar $filename`",$1" > work1.txt
printf "\n" >> work2.txt;
echo "worker.$1.host=127.0.0.1" >> work2.txt
echo "worker.$1.port=$2" >> work2.txt
echo "worker.$1.type=ajp13" >> work2.txt
echo "worker.$1.lbfactor=1" >> work2.txt

#Merge those two part as a file
cat work1.txt work2.txt> $filename

#Clean those tmp files
rm -rf work1.txt work2.txt
